/**
* 新增-手册程序（首页新增）
*/
<template>
    <div class="p10">
    <el-tabs type="border-card" >
        <el-tab-pane >
            <template #label><vp-label zh="基本信息" en="Basic Info"/></template>
            <QualityManual ref="manualRef"  :type="type"></QualityManual>
        </el-tab-pane>
    </el-tabs>
        <StatusBar
            :id="formData.id"
            :status="formData.zt"
            :isValid="formData.yxbs"
        />
        <PageBottom>
            <vp-btn-save :loading="saveLoading" @click="handleSave(10)"/>
            <VpProcessToolBar 
                :loading="saveLoading" 
                :set-loading-fn="(_loading: boolean) => { saveLoading = _loading }"
                :before-show-fn="beforeShowFn" 
                :after-agree-fn="afterAgreeFn"
            />    
        </PageBottom>
    </div>
</template>
<script setup lang="ts" name="AddManualRevision">
import other from '/@/utils/other';
import { onMounted, ref, watch, computed, reactive } from 'vue'
import request from '/@/utils/request';
import QualityManual from './QualityManual.vue';
import PageBottom from '/@/components/vp/PageBottom/index.vue';
import mittBus from '/@/utils/mitt';
import { useRoute } from 'vue-router';
import { ElMessage } from "element-plus";
import { useUserInfo } from '/@/stores/userInfo';
import { formatDate } from '/@/utils/formatTime';
import StatusBar from '/@/components/vp/status/StatusBar.vue';
import VpProcessToolBar from '/@/components/vp/workflow/VpProcessToolBar.vue';

const emits = defineEmits(['formSubmited']);
const loading = ref(false);
const saveLoading = ref(false);
const type = ref('add');

//from表单
const manualRef = ref();
//流程
const processHandleRef = ref();

const formData = reactive({
    id: '',
    zt: 10,
    yxbs: 1
});


const route = useRoute();
// 保存
const handleSave = (zt : number) => {
    saveLoading.value = true;
    manualRef.value.getData(zt).then((data: any) =>{
        request.post("/quality/manual/"+type.value, {
            ...data,
            zt: zt,
        }).then(()=>{
            mittBus.emit('onCurrentContextmenuClick', Object.assign({}, { contextMenuClickId: 1, ...route }));
            ElMessage.success(zt == 10 ? "操作成功/Success." : "办理完毕/Completed Processing");
        }).catch(()=>{
        }).finally(()=>{
            saveLoading.value = false;
        })
    }).catch(()=>{saveLoading.value = false;});
}


const beforeShowFn = () =>{
    saveLoading.value = true;
    return manualRef.value.getData(88).finally(()=>{saveLoading.value = false;});
}

const afterAgreeFn = (processHandle:any) =>{
    saveLoading.value = true;
    manualRef.value.getData(88).then((data: any) =>{
        request.post("/quality/manual/"+type.value, {
            ...data,
            zt: 88,
            processHandle: processHandle,
        }).then(()=>{
            mittBus.emit('onCurrentContextmenuClick', Object.assign({}, { contextMenuClickId: 1, ...route }));
            ElMessage.success("操作成功/Operation Succeeded");
        }).catch(()=>{
        }).finally(()=>{saveLoading.value = false;});
    }).catch(()=>{saveLoading.value = false;});
}

</script>
<style scoped lang="scss">
.card-header-center {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
</style>